<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 上午 10:21
 */
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use app\blog\model\GoodsModel as go;
class GoodsController extends AdminBaseController{
    /**
     * 商品列表页面
    */
    public function _initialize()
    {
        parent::_initialize();
        $this->go =new go();
    }

    public function indexs(){

    }
    public function index(){
        $array=$this->request->param();
        $cause='';
        if(isset($array['g_category']))
        {
          if($array['g_category'])
          {
              $cause['gc_guid']=$array['g_category'];
          }
        }
        /*商品类别*/
        $category_array=$this->go->category($cause,$state=1);
        $data=$this->go->index($array);
        $this->assign('data',$data['data']);
        $this->assign('category',$category_array);
        $this->assign('page',$data['page']);
        return $this->fetch();
    }
    /**
     * 添加商品页面
    */
    public function add(){
        $format=$this->go->format();
        $brand=$this->go->brand();
        $category_array=$this->go->category();
        $shop=$this->go->session();
        $this->assign('shop',$shop);
        $this->assign('category',$category_array);
        $this->assign('format',$format);
        $this->assign('brand',$brand);
        return $this->fetch();
    }
    /**
     * 添加商品操作
    */
    public function addpost(){
        $date = $this->request->post();
        $status=$this->go->add($date);
        $this->success($status);
    }
    /**
     * 修改商品页面
    */
    public function detail(){
        $date=$this->request->param();
        $where['goods_guid']=$date['goods_guid'];
        $state=$this->go->getone($where);
        $format=$this->go->format();
        $brand=$this->go->brand();
        $category_array=$this->go->category();
        $this->assign('category',$category_array);
        $this->assign('format',$format);
        $this->assign('brand',$brand);
        $this->assign('date',$state);
        return $this->fetch();
    }
    /*修改页面接收参数*/
    public function detailpost()
    {
        $date=$this->request->param();
        $state=$this->go->detail($date);
        $this->success($state);
    }
    /*删除商品*/
    public function del()
    {
        $date=$this->request->param();
        $state=$this->go->del($date);
        if($state['num']==1)
        {
          return   $this->success($state['con']);
        }else{
          return  $this->error($state['con']);
        }
    }

}